package com.ruoyi.project.mydo.mydojob.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.project.mydo.mydojob.domain.MydoJob;
import com.ruoyi.project.mydo.mydojob.service.IMydoJobService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 作业表Controller
 *
 * @author ruoyi
 * @date 2023-04-10
 */
@Controller
@RequestMapping("/mydo/mydojobin")
public class InMydoJobController extends BaseController
{
    private String prefix = "mydo";

    @Autowired
    private IMydoJobService mydoJobService;

    @GetMapping()
    public String mydojob()
    {
        return prefix + "/mydojobIn";
    }

    /**
     * 查询作业表列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MydoJob mydoJob)
    {
        startPage();
        mydoJob.setInOut(1);
        List<MydoJob> list = mydoJobService.selectMydoJobList(mydoJob);
        return getDataTable(list);
    }

    /**
     * 查询盘点入库作业表列表
     */
    @PostMapping("/pdinJoblist")
    @ResponseBody
    public TableDataInfo pdinJoblist(MydoJob mydoJob)
    {
        startPage();
        mydoJob.setInOrOut(mydoJob.getInOut().toString());
        List<MydoJob> list = mydoJobService.selectpdMydoJobList(mydoJob);
        return getDataTable(list);
    }

    /**
     * 查询盘点作业表列表
     */
    @PostMapping("/pdlist")
    @ResponseBody
    public TableDataInfo pdlist(MydoJob mydoJob)
    {
        startPage();
        mydoJob.setInOut(1);
        List<MydoJob> list = mydoJobService.selectpdMydoJobList(mydoJob);
        return getDataTable(list);
    }

    /**
     * 导出作业表列表
     */
    @Log(title = "作业表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MydoJob mydoJob)
    {
        List<MydoJob> list = mydoJobService.selectMydoJobList(mydoJob);
        ExcelUtil<MydoJob> util = new ExcelUtil<MydoJob>(MydoJob.class);
        return util.exportExcel(list, "作业表数据");
    }

    /**
     * 新增作业表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存作业表
     */
    @Log(title = "作业表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MydoJob mydoJob)
    {
        return toAjax(mydoJobService.insertMydoJob(mydoJob));
    }

    /**
     * 修改作业表
     */
    @GetMapping("/edit/{jobId}")
    public String edit(@PathVariable("jobId") String jobId, ModelMap mmap)
    {
        MydoJob mydoJob = mydoJobService.selectMydoJobByJobId(jobId);
        mmap.put("mydoJob", mydoJob);
        return prefix + "/edit";
    }

    /**
     * 修改保存作业表
     */
    @Log(title = "作业表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MydoJob mydoJob)
    {
        return toAjax(mydoJobService.updateMydoJob(mydoJob));
    }

    /**
     * 删除作业表
     */
    @Log(title = "作业表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(mydoJobService.deleteMydoJobByJobIds(ids));
    }

    /**
     * 手动完成
     * @param ids
     * @return
     */
    @RequestMapping("/handFinish")
    @ResponseBody
    public AjaxResult handFinish(String ids) {
        return mydoJobService.handFinish(ids);
    }

    /**
     * 手动作废
     * @param ids
     * @return
     */
    @RequestMapping("/handInvalid")
    @ResponseBody
    public AjaxResult handInvalid(String ids){
        return mydoJobService.handInvalid(ids);
    }

}
